$(() => {
    load();
});
const reLoad = () => {
    $('#exampleTable').bootstrapTable('refresh')
}

const totalScoreDecryption = (index) => {
    switch (index) {
        case 1:
            console.log('一键解密')
            let formitem='';
            for (let i = 1; i < 3; i++) {
                formitem += `
                      <div class="layui-form-item">
                            <label class="layui-form-label" style="width:auto;border: 0;">${i==1?'裁判长':'仲裁长'}</label>
                            <div class="layui-input-block">
                                <input type="text"   name="username${i==1?'':i}"  placeholder="请输入账号" autoComplete="off" class="layui-input">
                            </div>
                            <div class="layui-input-inline" style="width: calc(100% - 111px); margin-left: 38px;margin-top: 10px;  margin-right: 1px;">
                                 <input type="password"   name="password${i==1?'':i}"  placeholder="请输入密码" autoComplete="off" class="layui-input">
                            </div>
                        </div>`
            }
            layer.open({
                type: 1,
                area: ['500px', '60%'],
                title: "成绩总解密",
                shade: 0.6,
                shadeClose: false,
                maxmin: true,
                anim: 0,
                content: `
<form class="layui-form layui-form-pane" style="width: 100%;height: 100%;padding: 10px;" id="myForm">
    ${formitem}
  <div class="layui-form-item" style="display: flex;    justify-content: center;">
    <button class="layui-btn" type="button"  lay-submit lay-filter="layedit-code-yes">提交</button>
  </div>
</form>
                `,
                success: (layero, index) => {
                    layui.use(['form'], () => {
                        var form = layui.form;
                        form.render('select');
                        form.render();
                        form.on('submit(layedit-code-yes)', function (data) {
                            const mydata = data.field
                            console.log('==确定====',mydata)
                            $.ajax({
                                type: 'get',
                                data:  {
                                    ...mydata,
                                },
                                contentType: 'application/json',
                                url:"/updateStuDecrypt",
                                success: function (r) {
                                    if (r.code == 0) {
                                        layer.msg(r.msg);
                                        reLoad()
                                        layer.close(index);
                                    } else {
                                        layer.msg(r.msg);
                                    }
                                }
                            });

                        });
                    })
                }
            });
            break;
        case 2:
            console.log('导出成绩表')
            layer.confirm(`是否导出成绩表`, {
                btn1: function (index) {
                    window.location.href = '/downloadImportStu' ;
                    layer.close(index)
                }
            });
            break;
        case 3:
            console.log('导出成绩公示表')
            layer.confirm(`是否导出成绩公示表`, {
                btn1: function (index) {
                    window.location.href = "/documentWord";
                    layer.close(index)
                }
            });
            break;
    }
}
const columns =  [
    {
        field: 'unitName',
        // title: '<span style="position: relative; top: 12px;    overflow: hidden;">参赛单位</span>'+'<br>'+'<span style="opacity: 0">xx</span>',
        // title: '<div style="height: 46px;line-height: 46px;">参赛单位</div>',
        title: '参赛单位',
        //width: '105px',
    },
    {
        field: 'teamLeader',
        title: '领队',
    },
    {
        field: 'teacher',
        title: '指导老师',
    },
    {
        field: 'recordNumber',
        title: '检录序号',
    },
    {
        field: 'nameA1',
        title: '选手姓名',
    },
    {
        field: 'num1A1',
        title: '制定照护计划'+'<br>'+'一次加密',
    },
    {
        field: 'num2A1',
        title: '制定照护计划'+'<br>'+'二次加密',
    },
    {
        field: 'scoreA1',
        title: '制定照护计划'+'<br>'+'裁判打分',
    },
    {
        field: 'nameA2',
        title: '选手姓名',
    },
    {
        field: 'num1A2',
        title: '制定照护计划'+'<br>'+'一次加密',
    },
    {
        field: 'num2A2',
        title: '制定照护计划'+'<br>'+'二次加密',
    },
    {
        field: 'scoreA2',
        title: '制定照护计划'+'<br>'+'裁判打分',
    },
    {
        field: 'totalScoreA',
        title: '制定照护计划'+'<br>'+'最终得分',
    },
    {
        field: 'nameC1',
        title: '选手姓名',
    },
    {
        field: 'num1C1',
        title: '职业素养'+'<br>'+'一次加密',
    },
    {
        field: 'num2C1',
        title: '职业素养'+'<br>'+'二次加密',
    },
    {
        field: 'scoreC1',
        title: '职业素养'+'<br>'+'赛场得分',
    },
    {
        field: 'nameC2',
        title: '选手姓名',
    },
    {
        field: 'num1C2',
        title: '职业素养'+'<br>'+'一次加密',
    },
    {
        field: 'num2C2',
        title: '职业素养'+'<br>'+'二次加密',
    },
    {
        field: 'scoreC2',
        title: '职业素养'+'<br>'+'赛场得分',
    },
    {
        field: 'totalScoreC',
        title: '职业素养'+'<br>'+'最终得分',
    },
    {
        field: 'num1B1',
        title: '居家场景'+'<br>'+'一次加密',
    },
    {
        field: 'num2B1',
        title: '居家场景'+'<br>'+'二次加密',
    },
    {
        field: 'scoreB1One',
        title: '居家场景'+'<br>'+'婴幼儿照护打分',
    },
    {
        field: 'scoreB1Two',
        title: '居家场景'+'<br>'+'产妇照护打分',
    },
    {
        field: 'totalScoreB1',
        title: '居家场景'+'<br>'+'最终得分',
    },
    {
        field: 'num1B2',
        title: '月子场景'+'<br>'+'一次加密',
    },
    {
        field: 'num2B2',
        title: '月子场景'+'<br>'+'二次加密',
    },
    {
        field: 'scoreB2One',
        title: '月子场景'+'<br>'+'婴幼儿照护打分',
    },
    {
        field : 'scoreB2Two',
        title : '月子场景'+'<br>'+'产妇照护打分',
    },
    {
        field : 'totalScoreB2',
        title : '月子场景'+'<br>'+'最终得分',
    },
    {
        field : 'totalAverageScore',
        title : '团队得分',
    }
]
columns.forEach(item => {
    item.align = 'center'
    item.valign='middle'
})

function load() {
    $('#exampleTable')
        .bootstrapTable(
            {
                method: 'get', // 服务器数据的请求方式 get or post
                url:'/stuDecryptList', // 服务器数据的加载地址
                iconSize: 'outline',
                toolbar: '#exampleToolbar',
                striped: true, // 设置为true会有隔行变色效果
                dataType: "json", // 服务器返回的数据类型
                pagination: true, // 设置为true会在底部显示分页条
                singleSelect: false, // 设置为true将禁止多选
                // contentType : "application/x-www-form-urlencoded",
                // //发送到服务器的数据编码类型
                pageSize: 10, // 如果设置了分页，每页数据条数
                pageNumber: 1, // 如果设置了分布，首页页码
                //search : true, // 是否显示搜索框
                showColumns: false, // 是否显示内容下拉框（选择显示的列）
                sidePagination: "server", // 设置在哪里进行分页，可选值为"client" 或者 "server"
                queryParamsType: "",
                fixedColumns: false,
                //fixedNumber: 3,
                queryParams: function (params) {
                    console.log('params', params)
                    return {
                        pageNumber: params.pageNumber,
                        pageSize: params.pageSize
                    };
                },
                responseHandler: function (res) {
                    if (res.code !== '0') {
                        layer.msg(res.msg);
                        return false
                    }
                    return {
                        "rows": res.data.records,
                        ...res.data
                    };
                },
                columns
            });
}